import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/Home.vue'
import About from '../views/About.vue'
import Products from '../views/Products.vue'
import News from '../views/News.vue'
import Production from "../views/Production.vue";
import Artists from "../views/Artists.vue";
import Opus from "../views/Opus.vue";
import NewsDetail from "@/components/news/NewsDetail.vue";
import Endorsement from "@/views/Endorsement.vue";
import NewsList from "@/components/news/NewsList.vue";

const routes = [
    {
        path: '/',
        name: 'Home',
        component: Home,
        meta: { keepAlive: true } // ✅ 首页缓存
    },
    {
        path: '/about',
        name: 'About',
        component: About,
        meta: { keepAlive: true }
    },
    {
        path: '/products',
        name: 'Products',
        component: Products,
        meta: { keepAlive: true }
    },
    {
        path: '/news',
        name: 'News',
        component: News,
        meta: { keepAlive: true },
        children: [
            {
                path: '', // 没有参数时
                name: 'NewsList',
                component: NewsList,
            },
            {
                path: ':id', // 有参数时
                name: 'NewsDetail',
                component: NewsDetail,
                props: true
            }
        ]
    },
    {
        path: '/opus',
        name: 'Opus',
        component: Opus,
        meta: { keepAlive: true }

    },
    {
        path: '/artists',
        name: 'Artists',
        component: Artists,
        meta: { keepAlive: true }
    },
    {
        path: '/production',
        name: 'Production',
        component: Production,
        meta: { keepAlive: true }
    },
    {
        path: '/endorsement/:id',
        name: 'Endorsement',
        component: Endorsement,
        meta: { keepAlive: true }
    },
]

const router = createRouter({
    history: createWebHistory(), // 你当前使用的 history 模式
    routes,
    // 添加 scrollBehavior 选项
    scrollBehavior(to, from, savedPosition) {
        // 始终滚动到页面顶部
        return { top: 0 }
    }
})

export default router
